package File;

import java.io.File;
import java.io.IOException;
import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86136
 * Date: 2025-04-28
 * Time: 19:05
 */
public class Demo1 {
    public static void main(String[] args) {
//        File file = new File("F:/homework/computer/test.text");
        File file = new File("./test.text");
        System.out.println(file.getParent());
        System.out.println(file.getName());
        System.out.println(file.getPath());
        System.out.println(file.getAbsoluteFile());
        try {
            System.out.println(file.getCanonicalFile());
        } catch (IOException e) {
            e.printStackTrace();
        }
        System.out.println("----创建文件----");
        File file1 = new File("./test.text");
        try {
            boolean ret = file1.createNewFile();
            System.out.println(ret);
        } catch (IOException e) {
            e.printStackTrace();
        }
        System.out.println(file.exists());
        System.out.println(file.isDirectory());
        System.out.println(file.isFile());
        System.out.println("-----创建目录-----");
        File file2 = new File("./demo");
        boolean ret2 = file2.mkdir();
        System.out.println(ret2);
        System.out.println(file2.exists());
        System.out.println(file2.isDirectory());
        System.out.println(file2.isFile());
        System.out.println("----删除----");
        System.out.println(file2.delete());
        System.out.println(file1.delete());
        System.out.println(file.delete());

        File file3 = new File("F:/homework/computer");
        System.out.println(Arrays.toString(file3.list()));
        System.out.println(Arrays.toString(file3.listFiles()));
        File file4 = new File("./demo.text");
        try {
            file4.createNewFile();
        } catch (IOException e) {
            e.printStackTrace();
        }
        file4.deleteOnExit();
//        try {
//            Thread.sleep(10000);
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        }

        File file5 = new File("./demo2");
        try {
            System.out.println(file5.createNewFile());
        } catch (IOException e) {
            e.printStackTrace();
        }
        File file6 = new File("./dir/demo2");
        boolean ret = file5.renameTo(file6);
        System.out.println(ret);
    }
}
